<?php
/* @var $this NewsController */

$this->breadcrumbs=array(
	'News',
);
?>
<div class="container white-bg" id="<?php echo $this->id.'-page'?>">
   <div class="slide-container relative">
   <!-- Slideshow 1 -->
    <ul class="rslides" id="slide-show">
      <li><img src="images/1.jpg" alt=""></li>
      <li><img src="images/2.jpg" alt=""></li>
      <li><img src="images/3.jpg" alt=""></li>
    </ul>
   </div>
   
   <div class="slogan relative text-center">
      <p>Chào mừng bạn đến với website Bất Động Sản</p>
      <span class="absolute">Nơi mang lại cho bạn những thông tin kết nối hữu ích</span>
   </div>
   <div class="main-content">
      <div class="left">
         <div class="list-news">
            <div class="caption-label relative left"> 
               <em class="arrow half-arrow-down sprite absolute"></em>
               <span class="font-opensans">Tin mới nhất</span>
            </div>
            <div class="clear"></div>
            <?php if(count($list_news_newest) > 0){?>
               <ul>
                  <?php 
                  $i = 0;
                  foreach($list_news_newest as $model){
                     $i++;
                     $link = $model->linkDetail($model->news_id,$model->news_title);
                     ?>
                  <?php if($i == 1){?>
                     <li class="news-item large-item">
                        <a href="<?php echo $link?>">
                           <div class="img-wrap left">
                              <img src="<?php echo Yii::app()->params['path_image_news'].$model->news_image?>" />
                           </div>
                        </a>
                        <div class="text">
                           <a href="<?php echo $link?>" class="title bold font-opensans"><?php echo $model->news_title?></a>
                           <div class="summary">
                              <?php echo Str::cutString(Str::removeHTML($model->news_content),250)?>
                           </div>
                        </div>
                     </li>
                  <?php }?>
                  <?php if($i == 1){?>
                     <div class="clear"></div>
                  <?php }?>
                  <?php if($i > 1 && $i < 5){?>
                     <li class="news-item medium-item <?php if($i == 2) echo 'no-margin-left'?>">
                        <a href="<?php echo $link?>">
                           <div class="img-wrap ">
                              <img src="<?php echo Yii::app()->params['path_image_news'].$model->news_image?>" />
                           </div>
                           <div class="title">
                              <span class="font-opensans"><?php echo $model->news_title?></span>
                           </div>
                        </a>
                     </li>
                  <?php }?>
                  <?php if($i == 5){?>
                     <div class="clear"></div>
                  <?php }?>
                  <?php if($i > 4 && $i < 8){?>
                     <li class="news-item small-item ">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $model->news_title?></a>
                     </li>   
                  <?php }?>
                  <?php }?>
                  
                  <div class="clear"></div>
               </ul>   
            <?php }?>
            
         </div>
         
         <div class="list-news most-read">
            <div class="caption-label relative left"> 
               <em class="arrow half-arrow-down sprite absolute"></em>
               <span class="font-opensans">Tin nhiều người đọc</span>
            </div>
            <div class="clear"></div>
            <?php if(count($list_news_most_read) > 0){?>
            <ul>
               <?php 
                  $j = 0;
                  foreach($list_news_most_read as $model){
                     $j++;
                     $link = $model->linkDetail($model->news_id,$model->news_title);
                     ?>
                  <?php if($j == 1){?>
                     <li class="news-item large-item left">
                        <a href="<?php echo $link?>">
                           <div class="img-wrap">
                              <img src="<?php echo Yii::app()->params['path_image_news'].$model->news_image?>" />
                           </div>
                           <span class="title bold font-opensans"><?php echo $model->news_title?></span>
                        </a>
                        <div class="text">
                           <div class="summary">
                              <?php echo Str::cutString(Str::removeHTML($model->news_content),150)?>
                           </div>
                        </div>
                     </li>
                  <?php }?>
                  <?php if($j > 1 && $j < 6){?>
                     <li class="news-item small-item <?php if($j == 2) echo 'no-padding-top'?>">
                        <a href="<?php echo $link?>">
                           <div class="img-wrap left">
                              <img src="<?php echo Yii::app()->params['path_image_news'].$model->news_image?>" />
                           </div>
                        </a>
                        <div class="text">
                           <div class="title">
                              <a href="<?php echo $link?>" class="font-opensans"><?php echo $model->news_title?></a>
                           </div>
                        </div>
                     </li>
                  <?php }?>
                  <?php }?>
               </ul>
               <?php }?>
         </div>
      </div><!-- End left-content-->
      <div class="right">
         <div class="search-container">
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-house"></i>Công cụ tìm kiếm</div>
            <?php 
               //Danh sach tinh thanh
               $list_province = array(0 => '-- Tỉnh/Thành Phố --'); // Danh sách các Tỉnh/Tp
               $province = new Province();
               $object = $province->findAll(array(
                  'order' => 'prv_order DESC, prv_name ASC',
               ));
               
               //Danh sach danh muc
               $list_category = array();
               $category = new Category();
               $all_cate = $category->getAll();
               $tree_cate = $category->getTree($all_cate);
               $tree_cate[0] = '-- Danh mục nhà đất --';
               if(count($object) > 0){
                  foreach($object as $item){
                     $list_province[$item->attributes['prv_id']] = $item->attributes['prv_name'];
                  }
               }
               $model = new Post();
               //Danh sach quan huyen
               $list_district = array(0 => '-- Quận/Huyện --');
               if($model->post_prv_id > 0){
                  $object = District::model()->getAllByPrvID($model->post_prv_id);
                  foreach($object as $item){
                     $list_district[$item['dis_id']] = $item['dis_name'];
                  }
               }
               
               //Danh sach cac du an
               $list_project = array(0 => '-- Dự án --');
               if($model->post_prv_id > 0){
                  $object = Project::model()->findAllByAttributes(array('prj_dis_id' => $model->post_dis_id));
                  foreach($object as $item){
                     $list_project[$item['prj_id']] = $item['prj_name'];
                  }
               }
               
               //Lua chon dien tich
               $list_area = array('0' => '-- Chọn mức giá --',
                                  '0,30' => 'Dưới 30 m2',
                                  '30,50' => '30 - 50 m2',
                                  '50,100' => '50 - 100 m2',
                                  '100,200' => '100 -200 m2',
                                  '200,500' => '200 - 500 m2',
                                  '500,1000' => '500 - 1000 m2',
                                  '1000' => 'Trên 1000 m2');
            ?>
            <?php $model = new Post();?>
            <div class="form-search" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
               <?php $form=$this->beginWidget('CActiveForm', array(
               	'id'=>Yii::app()->controller->id . '_' . Yii::app()->controller->action->id,
               	'action' => '/post',
                  'method' => 'GET',
                  'enableAjaxValidation'=>false,
                  'enableClientValidation'=>false
               )); ?>
               
               <?php echo $form->errorSummary($model,'Kiểm tra lại các giá trị bạn vừa nhập vào'); ?>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_cat_id',$tree_cate);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prv_id',$list_province);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_dis_id',$list_district);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prj_id',$list_project);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_area',$list_area);?>
               </div>
               <div class="row text-right relative">
                  <?php echo CHtml::submitButton('Tìm kiếm',array('id' => 'submit-search'))?>
               </div>   
               <?php $this->endWidget(); ?>
            </div> 
         </div> <!-- End search-container -->
         <div class="video-embed">
            <iframe width="310" height="205" src="//www.youtube.com/embed/Q87KqUk36w8" frameborder="0" allowfullscreen></iframe>
         </div>
         <div class="focus-last-week">
            <?php
               $criteria = new CDbCriteria();
               $criteria->offset = 0;
               $criteria->limit = 10;
               $criteria->order = 'news_view DESC';
               $list_news = News::model()->findAll($criteria);
            ?>
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-focus"></i>Tiêu điểm tuần qua</div>
            <div class="list-news">
               <ul>
                  <?php 
                     $news_model = new News();
                     foreach($list_news as $news){
                     $link = $news_model->linkDetail($news->news_id,$news->news_title)
                     ?>
                     <li class="news-item">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $news->news_title?></a>
                     </li>
                  <?php }?>
                  
               </ul>
            </div>
         </div><!-- End focus-last-week -->
      </div><!-- End right-content -->
   </div>
</div>
<script>
   $(document).ready(function(){
      $("#slide-show").responsiveSlides({      
        speed: 800,
        nav: true,
        pager: true,
        auto:true,
      });
      
      //Load district
      $("#Post_post_prv_id").change(function(){
         var prv_id = $(this).val();
         data = {'prv_id':prv_id};
         success = function(data){
            $("#Post_post_dis_id").html(data);
         }
         handleAjax('/district/SetDropListByPrvID','GET','',data,success);
      });
      
      //Load project
      $("#Post_post_dis_id").change(function(){
         var dis_id = $(this).val();
         data = {'dis_id':dis_id};
         success = function(data){
            $("#Post_post_prj_id").html(data);
         }
         handleAjax('/project/SetDropListByDisID','GET','',data,success);
      });
   });
</script>